每日一看 redis事务加锁之java操作 package com.czmec.redis.test; import redis.clients.jedis.Jedis; import redis.clients.jedis.Transaction; /** * Created by Administrator on 2016/12/6 0006. */ public class affairLock { /** * 加锁 */ public boolean transMethod(){ Jedis jedis=new Jedis("112.74.34.11",6379); int balance;//可用余额 int debt;//欠款 int amtTosutract =10;//实刷额度 jedis.watch("balance"); balance=Integer.parseInt(jedis.get("balance")); if(balance<amtTosutract){ jedis.unwatch(); System.out.println("modify"); return false; }else{ System.out.println("***********transaction"); Transaction transaction=jedis.multi(); transaction.decrBy("balance",amtTosutract); tr